const { defineConfig } = require('@vue/cli-service')
const Mock = require('mockjs')
    // 模拟商品列表数据
const { list } = Mock.mock({
    'list|40': [{
        'id|+1': 1,
        'image': '@image(200X200,@color)',
        'title': '@ctitle(3,50)',
        'price|1-100.1-2': 1
    }]
})
module.exports = defineConfig({
    transpileDependencies: true,
    devServer: {
        setupMiddlewares: (mid, dev) => {
            dev.app.get('/api/search', (req, res) => {
                const { value } = req.query
                res.send({
                    code: 200,
                    data: list.filter(item => item.title.includes(value))
                })
            })
            dev.app.get('/api/list', (req, res) => {
                const { pagination, pageNum } = req.query
                res.send({
                    code: 200,
                    data: list.slice((pagination - 1) * pageNum, pagination * pageNum),
                    total: list.length
                })
            })

            return mid

        }
    }
})